Skip to content

Add index to sliding_sync_connection_lazy_members on connection_position#19923

Open
erikjohnston wants to merge 1 commit into
developfrom
erikj/sss_lazy_index
Open

Add index to sliding_sync_connection_lazy_members on connection_position#19923
erikjohnston wants to merge 1 commit into
developfrom
erikj/sss_lazy_index

Conversation

@erikjohnston

Copy link
Copy Markdown
Member

This speeds up the cascading delete from sliding_sync_connection_positions, which without an index on connection_position requires a sequential scan of the whole table for each deleted position.

This speeds up the cascading delete from
`sliding_sync_connection_positions`, which without an index on
`connection_position` requires a sequential scan of the whole table for
each deleted position.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@erikjohnston erikjohnston marked this pull request as ready for review July 7, 2026 16:24
@erikjohnston erikjohnston requested a review from a team as a code owner July 7, 2026 16:24
@MadLittleMods MadLittleMods changed the title Add index to sliding_sync_connection_lazy_members on connection_position Add index to sliding_sync_connection_lazy_members on connection_position Jul 7, 2026
Comment thread changelog.d/19923.misc
@@ -0,0 +1 @@
Add an index to `sliding_sync_connection_lazy_members` to speed up deleting old sliding sync connection positions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This speeds up the cascading delete from sliding_sync_connection_positions, which without an index on connection_position requires a sequential scan of the whole table for each deleted position.

We already have an index on connection_key and we expect only two entries at a time.

Seems weird that an index would help.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sliding_sync_connection_lazy_members has a foreign key on connection_position, and so when we delete from sliding_sync_connection_positions postgres has to look for any matches on sliding_sync_connection_lazy_members.connection_position. It's not smart enough to be able to understand that it can lookup (connection_key, connection_position) (as that is not the FK)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, this is a wasteful index but I see 👍


self.db_pool.updates.register_background_index_update(
update_name="sliding_sync_connection_lazy_members_conn_pos_idx",
index_name="sliding_sync_connection_lazy_members_conn_pos_idx",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sucks that we already have sliding_sync_connection_lazy_members_pos_idx with a similar name already

Comment thread changelog.d/19923.misc
@@ -0,0 +1 @@
Add an index to `sliding_sync_connection_lazy_members` to speed up deleting old sliding sync connection positions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, this is a wasteful index but I see 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants